define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_mill/index' + location.search,
                    add_url: 'user_mill/add',
                    edit_url: 'user_mill/edit',
                    del_url: 'user_mill/del',
                    multi_url: 'user_mill/multi',
                    table: 'user_mill',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'cb_mill_id', title: __('Cb_mill_id')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'user.mobile', title: __('User.mobile')},
                        {field: 'user.avatar', title: __('User.avatar'),operate: false ,events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'cbmill.name', title: __('Cbmill.name')},
                        {field: 'cbmill.image', title: __('Cbmill.image'),operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'cbmill.production', title: __('Cbmill.production'), operate:'BETWEEN'},
                        {field: 'cbmill.type', title: __('Cbmill.type'), searchList: {"1":__('Cbmill.type 1'),"2":__('Cbmill.type 2')}, formatter: Table.api.formatter.status},

                        // {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'receive_num', title: __('Receive_num')},
                        {field: 'numcount', title: __('Numcount')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        // {field: 'cb_num', title: __('Cb_num'), operate:'BETWEEN'},
                        {field: 'is_receive', title: __('Is_receive'), searchList: {"1":__('Is_receive 1'),"2":__('Is_receive 2')}, formatter: Table.api.formatter.normal},

                        {field: 'one_make', title: __('One_make'), operate:'BETWEEN'},
                        // {field: 'termtime', title: __('Termtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});